#!/bin/bash
# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

set -e

source ci/buildkite/pipeline-pr/scripts/git-rev.sh

echo '# ---------------------------------------------------------------------------- #'
echo "#    Diff between $BUILDKITE_PULL_REQUEST_BASE_BRANCH($BASE) and HEAD($HEAD)   #"
echo '# ---------------------------------------------------------------------------- #'

git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACM \
| rg -v "external|third_party|experimental|conversion\.h|test|bench" \
| rg "(\.cc|\.h)$" \
|| true

echo '# ---------------------------------------------------------------------------- #'
echo '#                               No slow function                               #'
echo '# ---------------------------------------------------------------------------- #'

set +e
git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACM \
| rg -v "external|third_party|experimental|conversion\.h|test|bench" \
| rg "(\.cc|\.h)$" \
| xargs -d '\n' rg \
  "(std::str?oull)|(std::str?oll)|(from_chars)|(std::to_string)"  # exit code = 1 if no match

[ $? -eq 1 ]

